﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Drawing;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Librerias;

namespace eCampusWeb
{
    public partial class MensajeCrear : System.Web.UI.Page
    {
        ENMensaje men;
        protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if ((Session["correo"].ToString() == "-1") || (Session["correo"].ToString() == ""))
                {
                    Response.Redirect("~/401.aspx");
                }

                string a = Request.QueryString["c"];

                if (a != null)
                {
                    TextBoxDestinatario.Text = a;
                }

            }
            catch
            {
                Response.Redirect("~/Default.aspx");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            string emisor;
            emisor = Session["correo"].ToString();
            try
            {
                new ENMensaje(emisor, TextBoxDestinatario.Text, TextBoxAsunto.Text,TextBoxMensaje.Text,"").Enviar();
                Response.Redirect("~/Mensajes.aspx");
            }
            catch (Exception ex)
            {
                if (ex.Message.ToString().Contains("usuCorreo"))
                {
                    LabelError.Visible=true;
                    LabelError.Text="El destinatario no existe en nuestro sistema" ;
                }              
            }
        }
        }
    }
